class Fund
  FIELDS = OrderedHash[
    :code , "基金代码", :name , "基金名称", :current_price , "单位净值", 
    :bi_annually_level , "两年评级", :annually_level , "一年评级",
    :weekly_rot , "周收益率", :weekly_rank , "周排名", :monthly_rot , "月收益率", :monthly_rank , "月排名", 
    :seasonly_rot , "季收益率", :seasonly_rank , "季排名", 
    :half_annually_rot , "半年收益率", :half_annually_rank , "半年排名",
    :annually_rot , "年收益率", :annually_rank , "年排名", :bi_annually_rot , "两年收益率", :bi_annually_rank , "两年排名",
    :current_year_rot , "当年收益率", :current_year_rank , "当年排名", :total_rot , "累计收益率",
    :fluctuating_range , "年波动幅度", :fluctuating_range_judgement , "波动幅度评价", 
    :risk_factor , "风险系数", :risk_judgement , "风险系数评价",
    :sharp_ratio , "夏普比率", :sharp_ratio_judgement , "夏普比率评价"]
  
  Fund::FIELDS.keys.each do |field|
    Fund.class_eval "attr_accessor :#{field}"
  end
  
  def self.fields
    FIELDS.keys
  end
  
  def self.field_label(field)
    FIELDS[field.to_sym]
  end
  
  def get(key)
    raise "FIELD #{key} DOES NOT EXIST" unless Fund::FIELDS.has_key? key.to_sym
    eval key.to_s
  end
  
  def get_as_float(key, default = 0.0)
    value = get(key).to_f
    value = default if value == 0.0
    return value
  end
  
end